#include <bits/stdc++.h>

using namespace std;

const int N = 100010;
const int M = 110;
int f[N][M][2];
int a[N];
int n, k;
int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; ++i)
    {
        scanf("%d", &a[i]);
    }
    memset(f, -0x3f, sizeof(f));
    for (int i = 0; i <= n; ++i)
    {
        f[i][0][0] = 0;
    }
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= k; ++j)
        {
            f[i][j][0] = max(f[i - 1][j][0], f[i - 1][j][1] + a[i]);
            f[i][j][1] = max(f[i - 1][j][1], f[i - 1][j - 1][0] - a[i]);
        }
    }
    int ret = 0;
    for (int j = 1; j <= k; ++j)
    {
        ret = max(ret, f[n][j][0]);
    }
    cout << ret << endl;
    return 0;
}